package com.ruleengine.parser.condition;

import org.apache.log4j.Logger;
import org.dom4j.Element;

import com.ruleengine.parser.IConditionParser;
import com.ruleengine.parser.ITaskContants;
import com.ruleengine.parser.exception.RuleEngineParserException;
import com.ruleengine.task.condition.ConditionFactory;
import com.ruleengine.task.condition.ICondition;

public abstract class BaseConditionParser implements IConditionParser {
    private static Logger logger = Logger.getLogger(BaseConditionParser.class);
    public ICondition parse(Element ele) throws RuleEngineParserException {
        // TODO Auto-generated method stub
        logger.debug("parse the node <"+ele.getName()+"> ");
        Element eleType = ele.element(ITaskContants.ELE_TAG_TYPE);
        String type = eleType.getTextTrim();
        ICondition condition =  ConditionFactory.getInstance().createCondition(type);
        condition = getCondition(condition,ele);
        return condition;
    }
    protected abstract ICondition getCondition(ICondition condition, Element ele ) throws RuleEngineParserException;
    
}
